<?php

// 查询配置
header('Access-Control-Allow-Origin:*'); //注意！跨域要加这个头 
// 连接数据库
require_once "./conn.php";
// require_once "./usersession.php";

if ($conn->connect_error) {
    die(json_encode(["Code" => 500, "Msg" => "连接错误: " . $conn->connect_error]));
}

// 获取前端传递的 JSON 数据
$data = json_decode(file_get_contents("php://input"), true);


// 提取中控账号和配置名
$zhongkong_account = $data['yunduan_zhanghao'];
$config_name =  $data['peizhiming'];

// 检查是否成功提取中控账号和配置名
if (empty($zhongkong_account) || empty($config_name)) {
    echo json_encode(["Code" => 400, "Msg" => "缺少中控账号或配置名", "Data" => ""]);
    exit;
}

// 查询配置
$sql = "SELECT settings FROM configurations WHERE zhongkong_name = '$zhongkong_account' AND name = '$config_name'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // 配置存在，返回 settings
    $row = $result->fetch_assoc();
   echo json_encode(["Code" => 200, "Msg" => "查询成功", "Data" => json_decode($row['settings'])], JSON_UNESCAPED_UNICODE);
} else {
    // 配置不存在，返回提示信息
    echo json_encode(["Code" => 404, "Msg" => "未找到对应的配置", "Data" => ""]);
}

$conn->close();
?>